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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append text if textbox not empty

Status
Not open for further replies.

Glowworm27

Programmer
May 30, 2003
587
US
Hello all java gurus,

Im a vb.net programmer, and am having trouble with this javascript.

I have a form with a textbox on it, and a button. when the user clicks the button another window opens with some values the user can select.

What I want to be able to do is when the user selects the value, insert that text back into the original forms textbox value.

I can do that, however the tricky part is I want the value to be appended with a preceding semicolon(;) then the value the user selected, if the textbox already has some data in it, otherwise just insert the value the user selected.

I have been tinkering with some existing javascript I have here could you please tell my why its not working

Code:
<script> if (window.opener.document.forms[0].TextBox1.value == "") { window.opener.document.forms[0].TextBox1.value = 'Accounting'} else {window.opener.document.forms[0].TextBox1.value += '; Accounting'}';self.close()</script>

Thanks in advance

George Oakes
Check out this awsome .Net Resource!
 
I found it,

I had a stray single quote(') in the end of the javascript

it should be....
Code:
<script> if (window.opener.document.forms[0].TextBox1.value == "") { window.opener.document.forms[0].TextBox1.value = 'Accounting'} else {window.opener.document.forms[0].TextBox1.value += '; Accounting'};self.close()</script>

Thanks

George Oakes
Check out this awsome .Net Resource!
 
Code:
<script> 
if (window.opener.document.forms[0].TextBox1.value == ""){   window.opener.document.forms[0].TextBox1.value = 'Accounting'} else {window.opener.document.forms[0].TextBox1.value += '; Accounting'}
self.close()
</script>

what type of error/results were you getting? this may work...
 
Just a suggestion...
Not to be critical or anything, but you may find your code easier to debug if it is indented to some extent, i.e.
Code:
// not this
if (sometest){alert('Yes');alert('No');alert('Maybe')}else{alert('No');}
// something like this
if (sometest)
{
  alert('Yes');
  alert('No');
  alert('Maybe');
}
else
{
  alert('Yes');
}

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
Chessbot,

Yes I agree indenting is proper!

The Code I had was created from several strings glued together, hence no proper indentation formating, and is passed under the covers to the opening page.

In code the individual lines are easy to read but dont have the typical formating a programmer would normaly see in a coded page.

I am injecting this code through .Net

Thanks

George Oakes
Check out this awsome .Net Resource!
 
Oh, ok.

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top