Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem getting parameter from url

Status
Not open for further replies.

mrDrive

MIS
Aug 29, 2002
94
US
Hi all,

I have a link on my page that allows users to add a title (heading) to the page. It does so by showing a textbox and button when they click on the "Click to add title" link. I'm basically trying to tack a "title" param to the current url like this:

Code:
<a href="javascript:;" onClick="document.getElementById('HiddenForm').style.display='block'; document.addTitle.titleBox.focus();">Click to add title</a>

<div id="HiddenForm" style="display: none;">
   <form style="margin-top: 0;" name="addTitle">
      <input name="titleBox" type="text" size="50">&nbsp;
      <input type="button" value="Add Title" onClick="document.location.href = document.location.href + '&title=' + document.addTitle.titleBox.value; document.location.reload();">
      &nbsp;<input type="button" onClick="document.getElementById('HiddenForm').style.display='none';" value="Cancel" />
   </form>
</div>

The code above fails, but when I wrap part of my onClick event in an alert() it works (section in bold below), but I also obviously get the alert which I don't need....

Code:
<a href="javascript:;" onClick="document.getElementById('HiddenForm').style.display='block'; document.addTitle.titleBox.focus();">Click to add title</a>

<div id="HiddenForm" style="display: none;">
   <form style="margin-top: 0;" name="addTitle">
      <input name="titleBox" type="text" size="50">&nbsp;
      <input type="button" value="Add Title" [B]onClick="alert(document.location.href = document.location.href + '&title=' + document.addTitle.titleBox.value); document.location.reload();"[/B]>
      &nbsp;<input type="button" onClick="document.getElementById('HiddenForm').style.display='none';" value="Cancel" />
   </form>
</div>

Thanks in advance for any help!
 
I had no problems using a function:
Code:
<script type="text/javascript">

function blah(str) {
   var page = String(document.location);
   document.location = page + "&title=" + str;
}

</script>
<input type="text" id="txt" />
<input type="button" value="click me" onclick="blah(document.getElementById('txt').value)" />

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top