@ilovelampauthorOct 09.2008 — #i got it wrong, i don't want to set a variable, i just want... well i can't explain it, so here: [CODE]function binary(frm) { if (frm.bin.value="2") alert("10") frm.Bin.value=="" else alert("please enter '2'") frm.Bin.value=="" } [/CODE] and I have this as well [CODE]<INPUT TYPE="TEXT" NAME="Bin"> <input type="button" name="binary" value="Convert" onClick="binary(this.form)">[/CODE] but when i click the button nothing happens. When i click the button i get no alert boxes, and that is why?
@justinbarneskinOct 10.2008 — #I see, you want to convert base10 numbers to ones and zeros. There is a function but last time I checked, IE doesn't handle it well so, I have not pursued it in awhile. I think it is radix(x) but that isn't it.
@skywalker2208Oct 10.2008 — #For one thing html should be in capital so it should be like this. [code=php] <input type="text" name="Bin"> <input type="button" name="binary" value="Convert" onClick="binary(this.form)"> [/code]
Also I am not 100% sure, but I don't think you could but this.form on the button to get all of the form values. You would have to put it on the form (<form>) element and use the onsubmit function. If you want to use the onclick on the button then you need to use the document.myform.Bin.value to get the value in the text field. You will also need to make sure to give the form element a name. for my example in using the document.myform.Bin.value I am using a form name of myform. I hope that helps.
@dongzkyOct 10.2008 — #i got it wrong, i don't want to set a variable, i just want... well i can't explain it, so here: [CODE]function binary(frm) { if (frm.bin.value="2") alert("10") frm.Bin.value=="" else alert("please enter '2'") frm.Bin.value=="" } [/CODE] and I have this as well [CODE]<INPUT TYPE="TEXT" NAME="Bin"> <input type="button" name="binary" value="Convert" onClick="binary(this.form)">[/CODE] but when i click the button nothing happens. When i click the button i get no alert boxes, and that is why?[/QUOTE]
i am not sure if it is just a typo error, but you must be confused with when to use "=" and "==" signs. your if comparison is not correct. you say
if (frm.bin.value="2") // only one equal (=) sign.
it should be
if (frm.bin.value=="2") //should be == for comparisons, the correct way
and for your assignment, you say:
frm.Bin.value=="" //"==" is not for assignments, should be "="
the correct way is
frm.Bin.value=""
Another thing, although maybe you have already, make sure that your form objects are inside a form tag (<form name="form_name" >)
And [B]change your function name "binary"[/B] to something else. It should not be the same as the name of your button, this will create a conflict. Just change it to something else like "fn_binary". In all, you will have something like below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
@ilovelampauthorOct 11.2008 — #here it is: <i> </i>function fn_binary(frm) { if (document.frmtest.Bin.value=="2") alert("10"); else alert("please enter '2'");
@dongzkyOct 11.2008 — #you don't have to say document.frmtest.Bin.value="". You can just write it as frm.Bin.value. Anyway, you mean your alert didn't work? what browser are you using? is your javascript enabled? have you checked if no script is blocked by your browser?
@ilovelampauthorOct 11.2008 — #no, i know that alert does work, I have made it work before, I'm using the latest version of safari, I know that javascript is enable and that no script is blocked form my browser