Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsDiscussion Forum → Javascript question
Javascript question
2007-11-23, 12:30 PM #1
How do I change a value when the form name isn't in quotes?
Code:
<form name=form action=# method=post>

is what I'm trying to work with. If I try
Code:
javascript:alert(document.form.Total.value="10"),
it doesn't work, but if I save the document and change
Code:
<form name=form action=# method=post>
to
Code:
<form name="form" action=# method=post>
it works. Any ideas on how to get around this?
2007-11-23, 12:46 PM #2
Follow the HTML standard and use quotes?


There is no reason not to put the quotes in.
TheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWho
SaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTh
eJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSa
ysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJ
k
WhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSays
N
iTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkW
2007-11-23, 12:52 PM #3
Yeah, I wasn't going to post because I'm not too familiar with javascript, but my first reaction was "so he just doesn't want to put quotes?" That's, as ni said, how you define anything in HTML/JS. Why do you need quotes for the value of 10? Why aren't you trying to get around that ;)
ᵗʰᵉᵇˢᵍ๒ᵍᵐᵃᶥᶫ∙ᶜᵒᵐ
ᴸᶥᵛᵉ ᴼᵑ ᴬᵈᵃᵐ
2007-11-23, 1:14 PM #4
This isn't a website I'm making -- I'm just testing my skills on another website...
2007-11-23, 1:21 PM #5
The problem is, the with the attribute set like that it will likely not actually be set at all.

What you can do, however, is use document.forms[0] (assuming that the form is the first form on the page, if it's the second then use document.forms[1].total

Which is basically the same as document.getElementsByTagName('form')[0];

If the browser is actually clever enough to set the name correctly, you may get away with being able to use document.getElementsByName('form')[0]

If 'total' is defined as an input and has a name you can use document.getElementsByName('Total');
TheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWho
SaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTh
eJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSa
ysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJ
k
WhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSays
N
iTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkW
2007-11-23, 1:43 PM #6
So, If I use javascript:alert(document.getElementsByName('Total').value=10) it should work? Because it doesn't. And yes, Total is an input with a name:
Code:
<input type=text NAME="Total" SIZE="7" MAXLENGTH="15" value="5000" onFocus="blur()">
2007-11-23, 1:54 PM #7
why don't you just provide a link to the page so we can tell you what will work?
Detty. Professional Expert.
Flickr Twitter
2007-11-23, 1:58 PM #8
I can't give the link unless you all want to create an account on the website to view it; however, I can do this:
Attachment: 17805/createhorse.txt (8,409 bytes)
2007-11-23, 2:06 PM #9
Strange, I just tried an unmodified copy of the document on my harddrive and javascript:alert(document.form.Total.value=10); works fine. Must be some sort of protection on the website, however I'm not sure what...

[Edit]Ahhh, I see now, theres multiple documents being used at once (I.E. home.php AND createhorse.php). Now my question is: Is there a way to select what document your changing?
2007-11-23, 2:08 PM #10
The clue is in the method you're using, getElementsByName.

It will return an array of all elements with the name specified, so just use the following instead:

javascript:alert(document.getElementsByName('Total')[0].value)
Detty. Professional Expert.
Flickr Twitter
2007-11-23, 2:13 PM #11
Nevermind my questions. I've figured the whole thing out.
Thank you everyone who tried to help, though.

↑ Up to the top!