How to check for Empty textboxed and fill it with a value on a button click

How to check for Empty textboxed and fill it with a value on a button click

Hi , i am making a project where there will be a text box with a Button beside it . when i enter a text in that box and click the button it should go of from the first text box and should be added to the target text box and sit should check if it is empty and should get added to the second target text box. the button should be disabled once i click it(i managed to do that), but when i'm trying to enter the text it is getting updated in the second target text box leaving the first blank, could you please help me out with this for all the target boxes, also forgot to mention the target textboxes are to be in read only mode. below is the code

<html>
<head>
<script type="text/javascript">
function move(){
    if(document.getElementById('tgt1').length==0)
{
 document.getElementById('tgt1').value = document.getElementById('Allocation').value;
}
else if(document.getElementById("tgt1").length!=0)
{
    document.getElementById('tgt2').value = document.getElementById('Allocation').value;
}
document.getElementById("Send").disabled=true;
}
function UnBlock()
{
    document.getElementById("tgt1").value="";
    document.getElementById("Send").disabled=false;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body {
    margin-top: 20px;
    margin-left: 30px;

}
</style>
</head>
<body>
<form name="myform">
<input type="text" name="Allocation" size="100" align="middle"> 
<input type="button" value="Allocate" id="Send" name="submit" onClick="move()"/><br/>
<br/><br/><br/><br/><br/><br/>
<table>
<tr>
<input type="text" id="tgt1" size="100"><td><input type="button" value="unlinkme" onclick="UnBlock()"</td>
<br/>
<input type="text" id="tgt2" size="100" >
<br/>
<input type="text" id="tgt3" size="100" readonly="true">
<br/>
<input type="text" id="tgt4" size="100" readonly="true">
<br/>
<input type="text" id="tgt5" size="100" readonly="true">
<br/>
<input type="text" id="tgt6" size="100" readonly="true">
<br/>
<input type="text" id="tgt7" size="100" readonly="true">
<br/>
<input type="text" id="tgt8" size="100" readonly="true">
<br/>
<input type="text" id="tgt9" size="100" readonly="true">
<br/>
<input type="text" id="tgt10" size="100" readonly="true">
<br/>
</form>
</body>
</html>

Thanks, Rakesh

View Answers

July 5, 2012 at 3:46 PM

Here is a code which check for Empty textbox and fill it with a value on a button click. When you enter a text in a textbox and click the button, it will get added to the target text box and check if second target box is empty. If it is empty, value will get added to the second target text box. The button will get disabled once you click it.

<html>
<script>
function dis(){
var v=document.getElementById("txt").value;
document.getElementById("txt1").value=v;
document.getElementById('txt1').readOnly=true;
var mystring=document.getElementById('txt2').value; 

if(!mystring.match(/\S/)){
document.getElementById("txt2").value=document.getElementById("txt1").value;
document.getElementById('txt2').readOnly=true;
}
document.getElementById("b").disabled=true;
}

</script>
<pre>
<input type="text" name="txt" id="txt">
<input type="button" id="b" value="Allocate" onclick="dis();">
Target Textbox1: <input type="text" id="txt1">
Target Textbox2: <input type="text" id="txt2">
</pre>
</html>









Related Tutorials/Questions & Answers:
How to check for Empty textboxed and fill it with a value on a button click
How to check for Empty textboxed and fill it with a value on a button... is a code which check for Empty textbox and fill it with a value on a button... with a Button beside it . when i enter a text in that box and click the button it should go
get a radio button click value - JSP-Servlet
get a radio button click value  thanks sir for sending code ,but i have one probs that is i m getting a null value i m calling getParameter("id... in the input tag name="radio" eventhough i m getting a null value please help me
Advertisements
check radio button on retrieving the value from database.
check radio button on retrieving the value from database.  HI i am... database and according to that i want to check the cash cheque radio button... information from database the i want to show cash radio button checked.How can i do
How to call java method on Button click in jsp?
How to call java method on Button click in jsp?  How to call java method on Button click in jsp
Check if the directory is empty or not
Check if the directory is empty or not In this section, you will learn how to check if the directory is empty or not. Java IO package works with both files and directories. Here we are going to check whether directory is empty
how to check the radio button automatically depending up on the value of database when editing the form...
how to check the radio button automatically depending up on the value... to highlight the radio button from the database.......nd even list box also can any... button. When the user clicks the particular radio button, that data will get shown
passing values on button click
passing values on button click  Please help me to solve this issue.I want to pass a value assigned to button to another view upon button click in xcode
on click button php
on click button php  Function in PHP for on click button
iphone button click event
iphone button click event  Hi, How to write iphone button click event? Thanks   Hi, Here the method declaration: -(IBAction) myMetod...{ NSLog(@"Button clicked"); } Thanks
jquery button click
jquery button click  jquery button click - I have created a button in JQuery but the problem is that it's not detecting click. What could...; <input id="Button1" type="button" value="button" />
click on check box
click on check box  I create a check box in HTML and when i click on my check box relative information in page store in database
Check Empty String
str): Use this method to check a string for its empty (" ) or null value... Check Empty String      ... str): This method is used to check whether a string is not empty (""), not null
How to check if an arraylist contains a value in Java
How to check if an arraylist contains a value in Java  Hi, I have an array list object in Java with few values. I want to check if it contains... to do this? How to check if an arraylist contains a value in Java? Thanks  
How to hide and show some field on a radio button click
How to hide and show some field on a radio button click  This is my... TYPE=radio NAME="payment_method" VALUE="cash" CHECKED><b class="label">..._method" VALUE="cheque" onclick="return payment();"><b class="label">
Show text field & check input using jQuery
will discuss about how to display 'text field' by a button click & check... how to display 'text field' by a button click & check input using jQuery. In the below example, a button is given when we click on it, 
how to remove spell check in flex when button is clicked
how to remove spell check in flex when button is clicked  how to remove spell check when button is clicked in rich text editor control
How to Display next Record from Database "On the Click of Next Button" USING ARRAYLIST
How to Display next Record from Database "On the Click of Next Button" USING ARRAYLIST  How to Display next Record from Database "On the Click of Next Button" USING ARRAYLIST,please send answer as soo as possible
java swing button click event
java swing button click event  java swing button click event   public void doClick()   Java Swing Tutorials
JFrame Button click to start play
JFrame Button click to start play  i made a game and and i add a button in new jframe and i want when i click it it start to play...can anyone help me
On Click on Submit Button Display Data on Orderlist
On Click on Submit Button Display Data on Orderlist  How can retreive data from database on orderlist on Click on submit Button of same page
executing multiple sql statements on the single button click...
executing multiple sql statements on the single button click...  how can i frame a code on the click of a button to insert data into a table as well as to retrieve records from the same table in another form
executing multiple sql statements on the single button click...
executing multiple sql statements on the single button click...  how can i frame a code on the click of a button to insert data into a table as well as to retrieve records from the same table in another form
how to check particular value is avilable in hashmap - Java Beginners
how to check particular value is avilable in hashmap  Hi friends, i created a hashmap,in that hashmap key is tagginglist and value is tagsname,these tags is in the form arraylist.then how i will check particular tags
JSP view detail page on accept button click
JSP view detail page on accept button click  i Have 1 jsp page in that there r 2 button accept and view details when we click on aceept button it will submit to next page and when click on view details page it will shown the data
How to fill double array in java
How to fill double array in java  how to fill double array in java
Draw a line in a JPanel with button click in Java
Draw a line in a JPanel with button click in Java  Draw a line in a JPanel with button click in Java
Moving Div by button click using animate effect
Moving Div by button click using animate effect In this tutorial , we will discuss how to move 'div' left-right by button click using jQuery. In this example , 'div' is moving left / right by left / right button click
How to make the single click as double click in java
How to make the single click as double click in java  How to make the single click as double click in java... By clicking on a tab, the tab should respond as clicked twice i.e (double click on the tab/button)... Its very urgent
Browser Back Button click event javascript
Browser Back Button click event javascript  I am using the below code but window.onBeforeUnload is not working with back button.. how can i apply the below code for the click event of back button? window.onBeforeUnload
How to add radio button value in a table for particular field?
How to add radio button value in a table for particular field?  Hi,I... one radio button for text field then it insert only one value absent OR present..." value="Submit" class="button" align="bottom" ></td> <
iPhone Button Click Sound
builder. If you don't know how to create the button then please check... iPhone Button Click Sound In this series of iPhone button tutorial, we... the application to listen the sound on button click. The sound file that i have used
click on back button go to the login page
click on back button go to the login page  now when i click on back button the page show that page on where i came from and it shows the session expired but i want when i click a back buttob then it should show a login page
Click On Images of Submit Button Perform Action
Click On Images of Submit Button Perform Action  I have login page in which insert of submit button i used image. Therefor on Click of image i have to validate form , link with database and goto the next page
How to show next question from database on the click of next button..(Struts & Hibernate)
How to show next question from database on the click of next button..(Struts.... Problem.: When m clicking my next button it is not showing another question...?pageName=2&iid=<%=Id%>"><img src="images/edit-icon.png" title="Click
How to show next question from database on the click of next button..(Struts & Hibernate)
How to show next question from database on the click of next button..(Struts.... Problem.: When m clicking my next button it is not showing another question...="images/edit-icon.png" title="Click Here To Update This Lists" alt="Click Here
How to Display next Record from Database "On the Click of Next Button" USING ARRAYLIST
How to Display next Record from Database "On the Click of Next Button" USING ARRAYLIST  In this code how i will use arraylist(which store all my records in index form) to show next data on button click,so that it will goes
How to Display next Record from Database "On the Click of Next Button" USING ARRAYLIST
How to Display next Record from Database "On the Click of Next Button" USING ARRAYLIST  In this code how i will use arraylist(which store all my records in index form) to show next data on button click,so that it will goes
Expand / Collapse form div when click on button
Expand / Collapse form div when click on button  Hi, I have a form... message appears but it takes more space than the DIV Formbox. How can I make the DIV...://fortwoplease.wufoo.com/forms/z7x3k7/" title="Squeeze Page" rel="nofollow">Fill out my Wufoo form
print form information when click on print button
print form information when click on print button   Sir,I desingn institute webside using jsp and strut by using platform netbean 7.2.So request you please help for printing form information by clickin print button after submit
passing value of radio button
passing value of radio button  hi,i have 3 jframe built using the GUi editor in net beans 6.9. i have two radio button in the first jframe.i have... frame.plz help me how can i do so? PLEASE note that all the codes
Open website on Button Click - Java Beginners
Open website on Button Click  Hello sir I want to open website on button click using java swing plz help me sir. in my swing application one "VISIT US BUTTON" i want to open my website on Button CLick  Hi Friend
change database values when click next button on jsp page
change database values when click next button on jsp page  How to retrive database values rondomly and display jsp page ,when user click next and previous bottons change the values on jsp page
SaveAs Dialogue box is not working on button click in servlet
SaveAs Dialogue box is not working on button click in servlet  Hii Sir, i added response.setHeader into my servlet code to export the data into excel file but this is not working on button click ...plz give me
to get radio button value - Struts
to get radio button value   hello friend, i have a problem regarding... two major problems:- 1.these radio button is not going to select also 2.i want to set the "value" attribute of radio button in the above code. Can u help
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???  How can change Button Label value Every Time when i start Virtual Keyboard, Means ,if 1st time Button1=''a'' then next login time
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???  How can change Button Label value Every Time when i start Virtual Keyboard, Means ,if 1st time Button1=''a'' then next login time
JQuery-check/uncheck radio button in jQuery
JQuery-check/uncheck radio button in jQuery  Hi Sir, I want to know how can i check/uncheck input or radio button?   You can check/uncheck radio button by setting the 'checked' attribute to true or false as follows
Struts 2 radio button value problem
Struts 2 radio button value problem  When I use s:radio tag in struts 2, I'm not able to get the selected value using document.getElementById('radioButtonName').value.(Note :- I'm getting proper value in java from jsp) It always
Fixed Value check using struts validator framework
Fixed Value check using struts validator framework  Hi All, can anyone tell me how to use struts validator framework for fixed value check. eg. country='India'; Thanks in advance
when i hit enter it represent action like click a button
when i hit enter it represent action like click a button  Hi, Plz provide a program in html like I want 2 submit buttons,when i hit the enter button it will represent the action like click the 1st submit

Ads