How to set Value of Input Using Javascript Function?

0 votes

I'm currently using a YUI gadget. I also do have a Javascript function to validate the output that comes from the div that YUI draws for me:

Event.on("addGadgetUrl", "click", function(){
    var url = Dom.get("gadget_url").value;  /* line x ------>*/
    if (url == "") {
        error.innerHTML = "<p> error" /></p>";
    } else {
        /* line y ---> */ 
        /*  I need to add some code in here to set the value of "gadget_url" by "" */
    }
}, null, true);

Here is my div:

<div>
<p>URL</p>
<input type="text" name="gadget_url" id="gadget_url" style="width: 350px;" class="input"/>
<input type="button" id="addGadgetUrl" value="add gadget"/>
<br>
<span id="error"></span>
</div>

As you can see my question is, how can I set the value of gadget_url to be ""?

Oct 7 in Java-Script by kartik
• 36,020 points
47 views

1 answer to this question.

0 votes

Hello @kartik,

Try for YUI

Dom.get("gadget_url").set("value","");

with normal Javascript

document.getElementById('gadget_url').value = '';

with JQuery

$("#gadget_url").val("");

Hope it helps!!

Thank you!

answered Oct 7 by Niroj
• 78,480 points

Related Questions In Java-Script

0 votes
1 answer

How to Scroll to the top of the page using JavaScript?

Hii @kartik, Using javascript <script> $("a[href='#top']").click(function() { ...READ MORE

answered Apr 2 in Java-Script by Niroj
• 78,480 points
84 views
0 votes
1 answer

How to get “value” of file upload input field in jquery?

Hello @kartik, Yes ,you can read the value ...READ MORE

answered Jul 7 in Java-Script by Niroj
• 78,480 points
1,453 views
0 votes
1 answer

How to convert an Object {} to an Array [] of key-value pairs in JavaScript?

Hello @kartik, You can use Object.keys() and map() to do this var obj ...READ MORE

answered Sep 4 in Java-Script by Niroj
• 78,480 points
162 views
0 votes
1 answer

How to reset <input type = “file”> using javascript?

Hello @kartik, You need to wrap <input type = ...READ MORE

answered Sep 18 in Java-Script by Niroj
• 78,480 points
281 views
0 votes
1 answer

How to access PHP var from external javascript file?

Hello @kartik, You don't really access it, you ...READ MORE

answered Jul 6 in Java-Script by Niroj
• 78,480 points
870 views
0 votes
1 answer

How do I escape a single quote in SQL Server?

Hello @kartik, Single quotes are escaped by doubling ...READ MORE

answered Jul 21 in PHP by Niroj
• 78,480 points
982 views
0 votes
1 answer

How to specify a port to run a create-react-app based project?

Hello @kartik, You could use cross-env to set the port, ...READ MORE

answered Jul 22 in Angular by Niroj
• 78,480 points
940 views
0 votes
1 answer

How do you set a default value for a MySQL Datetime column?

Hello @kartik, In version 5.6.5, it is possible ...READ MORE

answered Aug 18 in PHP by Niroj
• 78,480 points
439 views
0 votes
1 answer
0 votes
1 answer

How to get the value of an input field using ReactJS?

Hello @kartik, Managed to get the input field ...READ MORE

answered Oct 8 in Java-Script by Niroj
• 78,480 points
86 views