Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Translation

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,
Can someone translate this into real javascript?

Don't worry about giving it a function or don't call it from onclick or onsubmit, just try to make it a simple statement that could be easily pieced into an existing function.

Here is an example of what I need:

if ( document.form.submit.value == "Submit" )
{
then replace "submit" with == "Sending"

 
here it is:

(document.form.submit.value == "Submit")?document.form.submit.value="Sending":false;

good luck

 
I tried that, and had no success. Are you missing some part in the code? I'm guessing that the question mark indicates a replacement, if you can, make it where it is ready to insert into any function. I'm not able to make javascript from scratch.
 
OK. All I did was just a "simple statement" as you asked.
This is a complete statement and can be placed anywhere.

It is based on the basic javascript conditional expression with this syntax:

(condition) ? value1 : value2

If condition is true, the expression has the value of value1. Otherwise it is value2. It can be used as a standard expression, and it is also a good substitude for
if ... else ...

I tested it on this example:

<form>
<input type=&quot;button&quot; name=&quot;b1&quot; value=&quot;start&quot; onClick='(this.value==&quot;start&quot;)?this.value=&quot;stop&quot;:this.value=&quot;start&quot;'>
</form>

It changes button caption from &quot;start&quot; to &quot;stop&quot; and vice versa each time you press on it.

good luck
 
The first answer you gave was closest, and I used it to get an answer. See, I have validation in my scripting, so I didn't want the button to change unless it passed the validation first, that's why I wanted it ready to be passed into an existing function.

Here is what worked:

}
(document.info.submit.value == &quot;Submit&quot;)?document.info.submit.value=&quot;Sending&quot;:document.info.submit.value=&quot;Sending...&quot;;}

But if it weren't for you, I would not have made it, thanks a million.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top