views:

103

answers:

1

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!

+1  A: 

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.

Pointy
adding name="intranet" resulted in this being the linked to page: <?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?> <!DOCTYPE GSP (View Source for full doctype...)> - <GSP VER="3.2"> <TM>0.000363</TM> <Q /> <PARAM name="intranet" value="" original_value="Search+Intranet.." /> <PARAM name="ie" value="UTF-8" original_value="UTF-8" /> <PARAM name="ip" value="155.34.21.151" original_value="155.34.21.151" /> <PARAM name="access" value="p" original_value="p" /> <PARAM name="sort" value="date:D:L:d1" original_value="date%3AD%3AL%3Ad1" /> </GSP>
jake