Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error while writing Scirpt code in action attirbute of form tag in html

    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>

  • #2
    New Coder
    Join Date
    May 2010
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post
    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()"/>

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    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.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •