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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filling in a form with a hyperlink 1

Status
Not open for further replies.

emozley

Technical User
Joined
Jan 14, 2003
Messages
769
Location
GB
Hi,

I have a form which posts to an <iframe> on the same page. The idea is that as you type in an author's name in the form the list of possible matches gets shorter and shorter. Eventually I want to make it so once you see your match you can then click on it and it will fill in the box you were typing in with the whole match.

Is this possibe? I did something similar for another app but that time the link and the text were on the same page:

<script type="text/javascript">
function setStartEndDates(_start, _end) {
var f = document.forms['form'];
if (_start != '') f.elements['StartDate'].value = _start;
if (_end!= '') f.elements['EndDate'].value = _end;
}
</script>

and the link was:

<a href="javascript:setStartEndDates('08/08/2006','15/08/2006');">Last 7 days</a>
 
to access an iframe's form from it's parent page, try:

Code:
window.frames['iframeName'].document.forms['iframeFormName'].elements['elementName'].value

to do the reverse, try:

Code:
parent.document.forms['parentFormName'].elements['blah'].value;



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Fantastic thank you - I have noticed that if there is a ' in the string that is being passed to the function then it errors. I tried replacing ' with '' which normally works with ASP but am getting an error:

Error Expected ')'

My function now looks like this:

<script type="text/javascript">
function setAuthor(_author) {
var f = parent.document.forms['form'];
if (_author != '') f.elements['Author'].value = _author;
}
</script>
 
I've made this as a test and if the link has an apostrophe in it then it fails:

<body link="blue" alink="blue" vlink="blue">

<script type="text/javascript">
function setAuthor(_author) {
var f = parent.document.forms['form'];
if (_author != '') f.elements['Author'].value = _author;
}
</script>


<form name="form">
<input type="text" name="Author">
</form>

<font face='verdana' size='1'>
<a href="javascript:setAuthor('Banks, R C I'A');">
Banks, R C I'A</a></font><br>
 
Just realised it's this line here:

<a href="javascript:setAuthor('Banks, R C I'A');">

It's looking for a ) after the I' - is it possible to change it so you can pass a ' as a parameter?
 
Still no luck - it puts 'undefined' into the form.

E.
 
[tt]<font face='verdana' size='1'>
<a href="javascript:setAuthor('Banks, R C I\'A');">
Banks, R C I'A</a></font><br>
<font face='verdana' size='1'>
<a href="#" onclick="setAuthor(this.innerHTML);return false;">
Banks, R C I'A</a></font><br>
[/tt]
 
Perfect! Thanks very much (a well deserved star) - in the end I used a bit of ASP to replace the character. Ended up with:

Do While Not TBL.EOF
If TBL("Author")<>"" And IsNull(TBL("Author"))=FALSE Then
AuthorString=Replace(TBL("Author"),"'","\'")
Response.Write("<font face='verdana' size='1'>")
%>
<a href="javascript:setAuthor('<% = AuthorString %>')">
<%
Response.Write(TBL("Author")) & "</a></font><br>"
End If
TBL.MoveNext
Loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top