File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes How to retrieve string representation of <INPUT> value? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to retrieve string representation of <INPUT> value?" Watch "How to retrieve string representation of <INPUT> value?" New topic
Author

How to retrieve string representation of <INPUT> value?

Daniel Martin
Greenhorn

Joined: Aug 07, 2008
Posts: 11
As the topic describes, how is it done?

I thought that by default, the value of a form input field is a string. I need to retrieve substrings of the input string but I have not been able to achieve that.

Any ideas?

For instance, say I have the following INPUT tag.

If I copy and paste the code below from a YouTube page into the INPUT tag, I would like to parse it later on with Javascript. I assume that it would be stored as a string.

How do I do this?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You can access the value of the input element by element.value.
Daniel Martin
Greenhorn

Joined: Aug 07, 2008
Posts: 11
Yes, I know that. I am using that to pass the value into a Javascript function. In the function is where I am having problems.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Form submission has nothing to do with JavaScript. I assume you are trying to do something with the value before the form is submitted?

If so, you'll need to be more specific about whatever problems you are having.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Daniel Martin wrote:Yes, I know that. I am using that to pass the value into a Javascript function. In the function is where I am having problems.
Please elaborate about those problems then. As far now it's all too vague. What are the functional requirements? What do you have? What happens now? What happens not? What do you want to end up?
Daniel Martin
Greenhorn

Joined: Aug 07, 2008
Posts: 11
Sorry, I don't know of a good way of explaining it but I'll try to expand on what I said on the first post. I have an open source HTML editor that I got from http://www.openwebware.com/. I am trying to add further functionality to it, like the ability to add YouTube videos, Java Applets, templates, and so on.

I already created the YouTube button. When pressed, a popup page shows up by the following code:


The WYSIWYG.insertYouTube function is as follows:

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Well you probably should be using a normal button and not a submit button.

When you debug your code is alert(code.substr(0,12)) giving you anything?

Eric
Daniel Martin
Greenhorn

Joined: Aug 07, 2008
Posts: 11
^^ Nope, nada, just an empty alert popup.

I am using the submit button because all other existing popup menus follow this scheme and they work. So I tried following the same.
Daniel Martin
Greenhorn

Joined: Aug 07, 2008
Posts: 11
Daniel Martin wrote:^^ Nope, nada, just an empty alert popup.


I'm sorry, the <OBJECT> code copied from YouTube does show up in the alert message. I initially did it wrong when you asked.

So what does this mean???
Daniel Martin
Greenhorn

Joined: Aug 07, 2008
Posts: 11
Alright, I finally got it!

Basically, all I did was use the toString function call on the code parameter argument of my insertYouTube function. From there, I was able to parse the string using substr , indexOf, and so on.

So to some it up, I was able to achieve my goal of inserting a YouTube video into my page editor.


Thanks for all your help folks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to retrieve string representation of <INPUT> value?