/    Sign up×
Community /Pin to ProfileBookmark

help with javascript and text input

hello everyone reading this!

I have made a simple script to change a link depending on some information a user answers. The script i have mad works only halfway. I have found i can make it work with a prompt box bu thats not really what i want.

Heres the script

[quote]

<head>
<form method=”get” id=”input1″ name=”input1″>
<input type=’text’ name=”input2″ id=”input2″ title=”input your gamertag”/>
<button type=”submit” onclick=”writelink()”>GO</button></form>
<title>Untitled</title>
</head>
<body>

<script>

var dayarray=(“http://www.bungie.net/Stats/PlayerStats.aspx?player=“)
var text = (input1.elements[‘input2’].value)
function writelink(){
document.write(‘<a href=’);
document.write(”+dayarray+””+text+”);
document.write(‘>View My Stats</a><br>’);
document.write(“”+dayarray+””+text+””);
}
</script>

[/quote]

Try the script! it works but doesnt add the +text+ variable at the end of the link. it works if io change the

var text = (input1.elements[‘input2’].value)

to a prompt box

var text = prompt(type information here)

but i dont really want a prompt box.
I know this can be done but im a bit confsed, i think my var text = (input1.elements[‘input2’].value) is dodgy, but i don’t have enough knowldge of javascript to do this my self.

Thankyou! ?

to post a comment
JavaScript

16 Comments(s)

Copy linkTweet thisAlerts:
@LeruraSep 30.2005 — you must refer to that value this way:
[CODE]var text = document.input1.input2.value;[/CODE]
then your script wil work
Copy linkTweet thisAlerts:
@Fitzey_BoyauthorSep 30.2005 — hmm my editor shows no errors but the script still doesnt work. Thankyou for helping me sort out that line anyway. ?
Copy linkTweet thisAlerts:
@KravvitzSep 30.2005 — What does it not do that you want it to do?

Why did you use parentheses on this line?
var dayarray=("http://www.bungie.net/Stats/PlayerStats.aspx?player=")
var text = (input1.elements['input2'].value)
Copy linkTweet thisAlerts:
@Fitzey_BoyauthorSep 30.2005 — that line was something that got suggested to me, and then i started playin aroud with it to try to get it to work.

i share your confusion. the new and improved script seems perfect
Copy linkTweet thisAlerts:
@KravvitzSep 30.2005 — You don't seem to have answered my first question.

Do you really want the page to be overwritten with those document.write() calls?
Copy linkTweet thisAlerts:
@Fitzey_BoyauthorSep 30.2005 — ok let me explain.

this is for people who play an online game

they have an online identity called a gamertag

if they enter their gamertag i want the link to change, adding the gamertag to the end of that link to view that particualr person's stats for their gamertag

hope this answers your question
Copy linkTweet thisAlerts:
@Fitzey_BoyauthorOct 01.2005 — does anyone else see any other faults that i dont??
Copy linkTweet thisAlerts:
@CharlesOct 01.2005 — does anyone else see any other faults that i dont??[/QUOTE]1) You HTML is invalid.

2) You seem to be trying to write to the document's HEAD element.

3) You seem to be trying to write to the document after it has loaded.

4) A simple form would be much more simple.
Copy linkTweet thisAlerts:
@Fitzey_BoyauthorOct 01.2005 — Yeah i kinda figured that this was a crappy script. How would you suggest i write this in as a form? ive tried it bfore and came back with squat.

thanks for the input guys
Copy linkTweet thisAlerts:
@CharlesOct 01.2005 — What [i]exactly[/i] are you trying to do? What server side scripting do you have access to?
Copy linkTweet thisAlerts:
@Fitzey_BoyauthorOct 01.2005 — ok ive got the script working with a prompt box but im trying to get it to work with form elements

im trying to get it so the user inputs their specific information into the form, they submit the form, and the form is replaced by a link. that link is to a specific page for them, it is a link, with their information on the end.
Copy linkTweet thisAlerts:
@Fitzey_BoyauthorOct 01.2005 — i know it sounds shaky but i know what im doing, its kinda hard to explain
Copy linkTweet thisAlerts:
@CharlesOct 01.2005 — Why not have the FORM call the page "just for them"?
Copy linkTweet thisAlerts:
@Fitzey_BoyauthorOct 01.2005 — i dont know how, im kinda new to scripting, i learn it in school and thats it

? im a serious nooble
Copy linkTweet thisAlerts:
@KravvitzOct 01.2005 — They taught you about document.write()? Oy. Have they even mentioned DOM1, DOM2, or DOM3?

<form>s can not go in the <head> section.

You made this way more complicated than it needs to be.

&lt;form action="http://www.bungie.net/Stats/PlayerStats.aspx"
method="get" id="input1" name="input1"&gt;&lt;fieldset&gt;
&lt;legend&gt;View My Stats&lt;/legend&gt;
&lt;input type="text" name="player" id="player" title="input your gamertag" /&gt;
&lt;input type="submit" value="GO" /&gt;
&lt;/fieldset&gt;&lt;/form&gt;
Copy linkTweet thisAlerts:
@CharlesOct 01.2005 — Just keep in mind, that example above is not HTML. In HTML there are no trailling "/" thinggies.
×

Success!

Help @Fitzey_Boy 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 5.7,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...