Attribute value of <button> element

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I've this HTML code:

<form action="login.cgi" method="get">
<button id="btnAction" name="action" value="login">Prihlásiť</button>
</form>

But this JS code:
var val = document.getElementById('btnAction').getAttribute('value');
will return "Prihlásiť" instead of value "login" that I've designed.

Is there any workarround this? I'm very dissatisfied that MSIE is changing
my HTML code.
 
In Jozef Izso <[email protected]> had this to say:

My reply is at the bottom of your sent message:
Hi,

I've this HTML code:

<form action="login.cgi" method="get">
<button id="btnAction" name="action" value="login">Prihlásit</button>
</form>

But this JS code:
var val = document.getElementById('btnAction').getAttribute('value');
will return "Prihlásit" instead of value "login" that I've designed.

Is there any workarround this? I'm very dissatisfied that MSIE is
changing my HTML code.

I can't replicate that as changing my code loaded internally nor externally
as uploaded (though there was no login.cgi to post to it should not matter)
so I'm not sure what is going on. Are you sure it's IE and not the hosts?
Your HTML editor?

Galen
--

"And that recommendation, with the exaggerated estimate of my ability
with which he prefaced it, was, if you will believe me, Watson, the
very first thing which ever made me feel that a profession might be
made out of what had up to that time been the merest hobby."

Sherlock Holmes
 
Yes, I'm sure that this is IE problem. I'm not using the HTML editor.

Try this:

<form action="login.cgi" method="get"
onsubmit="alert(document.getElementById('btnAction').getAttribute('value'));
return false;">
<button id="btnAction" name="action" value="login">Prihlásiť</button>
</form>

Alert will show "Prihlásiť" instead of correct "login".
 
In Jozef Izso <[email protected]> had this to say:

My reply is at the bottom of your sent message:
Yes, I'm sure that this is IE problem. I'm not using the HTML editor.

Try this:

<form action="login.cgi" method="get"
onsubmit="alert(document.getElementById('btnAction').getAttribute('value'));
return false;">
<button id="btnAction" name="action" value="login">Prihlásit</button>
</form>

Alert will show "Prihlásit" instead of correct "login".

"Galen" wrote:

Yes it shows the prihlásit...

<form action="login.cgi" method="get"
onsubmit="alert(document.getElementById('btnAction').getAttribute('value'));
return false;">
<button id="btnAction" name="action" value="login">LOGIN</button>
</form>

Shows login... The value is just what is parsed - the text is what is seen
in the button. Thus prihlásit becomes login when you change it. You could
make it:

<form action="login.cgi" method="get"
onsubmit="alert(document.getElementById('btnAction').getAttribute('value'));
return false;">
<button id="btnAction" name="action" value="login">Sign On</button>
</form>

For example. That's what it's supposed to do?


The content not bracketed is the value passed to the browser the value is
the the action it will take. An attribute IIRC and not an element? Anyhow
the unbracketed text is what is displayed in the browser.

Example for simplicty?

<a href="www.example.com/somelink.html">Click this link to go visit
Example.com</a> The unbracketed text is displayed...

Galen
--

"And that recommendation, with the exaggerated estimate of my ability
with which he prefaced it, was, if you will believe me, Watson, the
very first thing which ever made me feel that a profession might be
made out of what had up to that time been the merest hobby."

Sherlock Holmes
 
I've localized application to German, Slovak and Czech thus I can't relly on
button's innerText value.

Internet Explorer badly sendes submit button's innerText property instead of
value="" atribute.

But why it changes the value="login" defined by me in code to
value="Prihlasit"?? If it doens't do this, I can before submiting <form>
change innerText property to value of value="" attribute. But whit this
behaviour I can't.

So I need to resolve this problem: How to stop IE to change MY attributes by
his crazy mind and will?? I've defined values of HTML tags atributes for some
reason, so WHY IE is changing them???
 
In Jozef Izso <[email protected]> had this to say:

My reply is at the bottom of your sent message:
I've localized application to German, Slovak and Czech thus I can't
relly on button's innerText value.

Internet Explorer badly sendes submit button's innerText property
instead of value="" atribute.

But why it changes the value="login" defined by me in code to
value="Prihlasit"?? If it doens't do this, I can before submiting
<form> change innerText property to value of value="" attribute. But
whit this behaviour I can't.

So I need to resolve this problem: How to stop IE to change MY
attributes by his crazy mind and will?? I've defined values of HTML
tags atributes for some reason, so WHY IE is changing them???

I still don't see where it's changing the attribute - it's using exactly
what you told it to use. The text in the non-bracketed area is what will be
displayed in ANY browser AFAIK. It's the standards not an IE
function/malfunction? The value is what the button will be doing when
pressed, the text that's not bracketed will be what's shown to the user.
It's not IE it's all browsers. You can just as easily swap out the value as
"login" with the word parsnips and open it with any standards compliant
browser and it's still going to show the data within the non-bracketed
sections. It shows as it's given - HTML is good like that.

Galen
--

"And that recommendation, with the exaggerated estimate of my ability
with which he prefaced it, was, if you will believe me, Watson, the
very first thing which ever made me feel that a profession might be
made out of what had up to that time been the merest hobby."

Sherlock Holmes
 
I'm not telling about "nonbracked" area (AKA element content, by the way).

I defined atributed value="" of <button> element like this:
<button value="login">Sign On</button>

So, when I want the value of the value="" attribute, in JS I will use:
button.getAttribute('value');

But this method doesn't return the right value "login" (which I defined) but
it returns "Sign On".

And I'm confused with this behaviour. (I really doesn't know any other way
of explanation of this problem.)
 
Another try:

When the <button> (which has default type="submit", but IE must have this
explicitly defined) is clicked, the form is being submited. But IE doesn't
return the content of value="" attribute, but the content of <button> element.

<button type="submit" name="btnButton" value="right value to submit">Another
IE bug. This text shouldn't be submited.</button>

And on the server side:
<script runat="server">
string val = Request.QueryString["btnButton"];
// in standars compliant browsers: val == "right value to submit" == true;
// in IE: val == "Another IE bug. This text shouldn't be submited." == true;
<script>

So I added the event hendler to form's submit event to change the innerText
property to content of value="" attribute.
<form onsubmit="button.innerText = button.value;">...</form>

But WHY in IE is this possible:
button.innerText == button.value; // true
"Another IE bug. This text shouldn't be submited." == "right value to
submit" // I think that this is FALSE
 
In Jozef Izso <[email protected]> had this to say:

<snip>

If you're convinced this is a bug (and that other browsers behave
differently) you probably should report it in the right place. This is a
public forum offered by Microsoft and not always monitored so in order to
get the attention to this bug from the right people this would probably be
the link you'd like to use:

Report:
http://support.microsoft.com/gp/contactbug

Galen
--

"And that recommendation, with the exaggerated estimate of my ability
with which he prefaced it, was, if you will believe me, Watson, the
very first thing which ever made me feel that a profession might be
made out of what had up to that time been the merest hobby."

Sherlock Holmes
 
Back
Top