...

View Full Version : Error while writing Scirpt code in action attirbute of form tag in html



Rajesh77
06-09-2010, 07:38 AM
Hi everyone


In the below code i tried to write java scirpt in action attribute of form tag in html . Why i wrote that was i want to get the scirpt variable as a part of the url of the target page .

I also tried using the location.href="targetpage?value="+value . But It is not redirecting to targetpage because of the action attribute in the form tag. And if we use location.href without action attribute only that script variable was posted and all other remaining textboxes and other form items are being not posted ..
Thats why I wrote the scirpt in action attribute. I want the action attribute to work and also the java script variable to be posted .so i wrote the script tag in action attribute of form tag .

I hope u got the Scenario .
Please help me to resolve the issue..
Thank in advance ..





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>


<? if($_POST['submit'] )
{
$var = $_GET['width'] ;
}
?>


<form name="form_submit" method="post" action="test2.php?width=
'<script type= text/javascript> document.write(num)</script>' " onsubmit="return fun(); ">

<script type="text/javascript">

function fun()
{
width = screen.width;
height = screen.height;
if (width > 0 && height >0) {
window.location.href = "http://localhost/test2.php?width=" + width + "&height=" + height;
} else
exit();

}
</script>

<input type="text" name="txt" value="sample text" />
<input type="submit" name="submit" value="submit" />

</form>
</body>
</html>

arizvi
06-09-2010, 11:27 AM
Do one thing...

1. Make submit button to simple button.
2. Add onclick with the button and set form action on this and submit the form.

<form name="form_submit" method="post" action="" onsubmit="return fun(); ">
<script type="text/javascript">

function setAction(){
document.forms[0].action = "http://...."+"?value="+num;
document.forms[0].submit();
}
</script>
<input type="text" name="txt" value="sample text" />
<input type="button" name="submit" value="submit" onclick="setAction()"/>

abduraooft
06-09-2010, 11:59 AM
In the below code i tried to write java scirpt in action attribute of form tag in html . Why i wrote that was i want to get the scirpt variable as a part of the url of the target page . Make some hidden input elements inside your form and then set their values when the page loads, using javascript.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum