HTML form not changing URL as expected

前端 未结 1 648
心在旅途
心在旅途 2020-12-22 12:46

I have a problem in my project that i cant fix yet. Im working with MySQL - PHP and everything is working OK but when I try to open \"php/consult.php?consult=add

相关标签:
1条回答
  • 2020-12-22 13:00

    This works if submitted - you don't need to add the query string - if it were an <a href="... then you would need the full query string for the url:

     <form action="php/test.htm" method="get">
             <td>Instruccion SQL:</td>
             <td>
             <input type="text" name="codecosult" required/>
             </td>
     <input type="submit" name="submit" value="Submit" />
     </form>
    

    This gives me my url + /php/test.htm?codecosult=ghrth&submit=Submit

    ghrth was what I had typed.

    If you are submitting it with a script leave the query string off and let the "GET" method deal with it - script here is in the head.

    <script language="javascript">function submit_this(){this.form.submit();}</script>
    
    </head>
        <body>
             <form name="form" id="form" action="php/test.htm" method="GET">
                      <td>Instruccion SQL:</td>
                      <td>
                      <input type="text" name="codecosult" id="codecosult" required/>
                      </td>
    
             <div onClick="submit_this();">Submit</div> 
    

    This gives me my url + test.htm?codecosult=dfthwrth

    dfthwrth was what I had typed.

    This also works, though the <a href="...'s hrefis modified here by the keypress event each time a key is pressed (may not work in all browsers):

     <input type="text" name="codecosult" onKeyPress="ahreff.href='php/test.htm?'+this.value;" required/>
     <a href="#" id="ahreff">Click Here</a>
    

    This might be of interest - a dropdown will pass its value in the same way:

    dropdown menu doesn't function - it will now!

    0 讨论(0)
提交回复
热议问题