简体   繁体   中英

pass url stored as string in variable to form's onsubmit

how can i make a form tag using onsubmit (that executes upon hitting enter) which opens a target window with a given url in a string variable form?

what i have so far:

<div id="row2">

 <!-- Intranet Search -->
 <form action="" onSubmit="urlGen(this);" method="get" target="_blank">
 <input type="text" id="intranet" size="15" value="Search Intranet.."
  onFocus="this.value = ''"
  onBlur="this.value = 'Search Intranet..'" / > 
 </form>

 <script language="javascript" type="text/javascript">
  function urlGen(f)
   {
    var i1 = "seg1";
    var i2 = f.intranet.value;
    var i3 = "seg3";

    var fullURL = i1 + i2 + i3;
    f.action = i1 + i2 + i3;

    //document.write(fullURL);

    return true;
   }
 </script>

<br><br>

 <a href="javascript: void(0)" onClick="urlGen();" target="_blank">
  <div id="submit" class="out"
   onMouseOver="document.getElementById('submit').className = 'over';"
   onMouseOut="document.getElementById('submit').className = 'out';">
   <span>Submit</span>
  </div>
 </a>
</div>

edit: still havent solved this; any help from someone more experienced with javascript would be greatly appreciated!

You need to give your <input> element a "name" value:

<input type="text" name="intranet" id="intranet" size="15" ...

Alternatively, your Javascript code could use document.getElementById("intranet") to get a reference to the input element.

Also, though this isn't directly relevant, putting a <div> inside an <a> tag is not valid markup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM