/    Sign up×
Community /Pin to ProfileBookmark

Write the value of a textbox somewhere else.

Hi,

I want to write a value of a textbox somewhere else in the page, is that possible?
Im pritty new to this whole javascript thing, but i did some attempts on this one. All i could think about is this:

[CODE]
<input name=”mytext” type=”text” value=”32″ />
<script type=”text/javascript”>
document.write(mytext);
</script>[/CODE]

Next thing is that i want that value (in this case mytext) in a link. I already tried

[CODE]<a href=’mytext’[/CODE]

but it didnt work out as well ?.

Well hope you can figure it out,

CyCloneNL

to post a comment
JavaScript

21 Comments(s)

Copy linkTweet thisAlerts:
@gphApr 08.2006 — I'm sure it's in [url=http://faqts.com/knowledge_base/index.phtml/fid/130]here[/url] somewhere. That site might help you learn
Copy linkTweet thisAlerts:
@CyClonenlauthorApr 08.2006 — Wow thanks, got the first part of the problem solved already. It will write the text i write in my textbox somewhere else.

Now all i need to know how to get that in a link.
Copy linkTweet thisAlerts:
@DracoMerestApr 08.2006 — You cannot 'easily' write to a page after it has loaded. Much easier to modify the contents of a layer.

Changing the link 'value' is a matter of assigning a new value to the HREF attribute of an ANCHOR object.

[CODE]<html>
<body>
<form>
<input type="text" name="someText">
<input type="button" value="Write" onclick="document.all.link.href=document.getElementById('showText').innerText=this.form.someText.value;">
</form>
<div id="showText"></div>
<a href="" name="link">Variable link</a>
</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@gphApr 08.2006 — The link text or href?
Copy linkTweet thisAlerts:
@CyClonenlauthorApr 08.2006 — I just want the people to write a site in a textbox and if they click go or something, they will go there.
Copy linkTweet thisAlerts:
@gphApr 08.2006 — well the simple answer is

<input type="text" onchange="window.location.href=this.value">
Copy linkTweet thisAlerts:
@gphApr 08.2006 — Just a note about the site I posted above.

It's useful for beginners but some questions are old. If you see something with "document.layers" or "document.all" use the modern equivalent document.getElementById('idStr')
Copy linkTweet thisAlerts:
@stephen1davisApr 08.2006 — try this:

<html>

<head>

</head>

<body>

<script type="text/javascript">

function goToIt() {

window.location="http://"+document.main.site.value

}

</script>


<form name="main" action="javascript:goToIt()">

<input name="site" type="text" value="type a site">

<input type="submit" value="Go!">

</form>

</body>

</html>
Copy linkTweet thisAlerts:
@gphApr 08.2006 — stephen1davis, just so you know, location is an object.

Changing the url with window.location is one of those things that works but is incorrect. You need to use the href property of the location object.
Copy linkTweet thisAlerts:
@stephen1davisApr 08.2006 — i see- you mean say location.href, but i still don't see what you mean about it being an object, and why isn't it correct?.
Copy linkTweet thisAlerts:
@stephen1davisApr 08.2006 — ok- i think i get it. you're saying that by using window.location=, you're not technically setting any properties for the object "location", and you should be setting the property "href". and of course "window" can be dropped anyway. (see, my education in javascript has been a little random...) makes good sense. thanks
Copy linkTweet thisAlerts:
@gphApr 08.2006 — One of the properties of location is href that can be use to get or set the location. The default property of location is href, so my saying it's "incorrect" is wrong.

It's like using the keyword "with". It leaves the script open to interpretation by a browser. Better safe than sorry by pointing to the property directly:

window.location.href=string

or just

location.href=string

because window is assumed
Copy linkTweet thisAlerts:
@CyClonenlauthorApr 08.2006 — Well thanks for all your solutions! You guys reply really fast.

Can this also be done in a Iframe?
Copy linkTweet thisAlerts:
@gphApr 08.2006 — Try this

<input type="text" onchange="top.location.href=this.value">
Copy linkTweet thisAlerts:
@CyClonenlauthorApr 08.2006 — But would it be possible to do that to iframes?
Copy linkTweet thisAlerts:
@gphApr 08.2006 — I think I see what you're saying, try this
<i>
</i>&lt;input type="text" onchange="document.getElementById('[COLOR=Red]iframeID[/COLOR]').src=this.value"&gt;
Copy linkTweet thisAlerts:
@CyClonenlauthorApr 08.2006 — Nice! Its working like a charm. But can i have a Go! button by just make one like this:

[CODE]<input name="Buttonname" type="submit" onchange="document.getElementById('tabiframe').src=this.value" />[/CODE]

(tabiframe is the name of the iframe)

// edit

Thats working too! Thanks a million!

Ok, but how can i add http:// automatic? That dosnt sounds hard.
Copy linkTweet thisAlerts:
@CyClonenlauthorApr 08.2006 — Ok, but how can i add http:// automatic? That dosnt sounds hard.
Copy linkTweet thisAlerts:
@balloonbuffoonApr 08.2006 — For a button, do this:
[code=html]<input name="Buttonname" type="button" value="Go!" onclick='document.getElementById("tabiframe").src="http://" + document.forms['formName'].elements['elementName'].value' />[/code]
You'll have to fill in the formname and element name (of the text box).

--Steve
Copy linkTweet thisAlerts:
@CyClonenlauthorApr 09.2006 — Ok thnx
Copy linkTweet thisAlerts:
@CyClonenlauthorApr 09.2006 — Huh.. it isnt really working.

I got this now:

[CODE]
<form name="form1">

//Adressbar
<input name="urlbox" type="text" style="WIDTH: 705px" onchange="document.getElementById('tabiframe').src=this.value" O value="http://www.google.nl">

//Go button
<input name="Buttonname" type="button" value="Go!" onclick='document.getElementById("tabiframe").src="http://" + document.forms['form1'].elements['urlbox'].value' />

</form> [/CODE]
×

Success!

Help @CyClonenl spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...