Javascript function to determine value in textbox

This should have been a realtively easy function to write.. but it seems as if there should be a quicker way to do part of it... can anyone give me a hand.
I have a text box the the user enters a code representing the page they want to go to. Depending on the page they want I set a variable. The code can be numbers or letters up to 6 in length. If the code comes in as XXXXDT then I do one thing.. this is done. But if the code comes in as TXXX I have to do something. I can check for the "T" but to check to make sure the other 3 digits are numeric I'm not sure what the best way would be. Can I just take the substring and do a parseInt on it... but if someone where to enter "TTTT" then the parseInt would crash... and I've never done any error handling in javascript.
this is the code I have so far
function goToNextScreen(frm){
              var url = window.location + "";     
              var pathPrepend ="";
              var newAction="&omniActionOrTab=Refresh";
              var screen = document.forms["GoToScreen"].screenName.value.toUpperCase();
              if(url.indexOf("/jsp") < 0)
                pathPrepend += "jsp/";     
               if(screen.length==6&&screen.substring(4)=="DT"){
                    newAction="&omniActionOrTab=Init";
               }else if(screen.length==4&&screen.substring(0,1)=="T"){
                               //do more here to check to make sure the next three characters
                              // are numbers.
               document.forms["GoToScreen"].action = pathPrepend + document.forms["GoToScreen"].screenName.value.toUpperCase() + ".do?useSessionKeys=true" + newAction;               
               alert("action = "+document.forms["GoToScreen"].action);
               return true;
          }          

I have never used regular expressions. So after reading the page you sent me this is what I came up with... but when I enter a value of "T444" the if statement is not being stepped into... could you tell me what I'm doing wrong?
function goToNextScreen(frm){
              var url = window.location + "";     
              var pathPrepend ="";
              var newAction="&omniActionOrTab=Refresh";
              var screen = document.forms["GoToScreen"].screenName.value.toUpperCase();
              tranRegexp = new RegExp("/T(\d){3}/");                 
              detailRegexp = new RegExp("/(\w){4}DT/");         
              if(url.indexOf("/jsp") < 0)
                pathPrepend += "jsp/";      
                alert("tranRegexp.exec(screen)="+tranRegexp.exec(screen));
                alert("detailRegexp.exec(screen)="+detailRegexp.exec(screen));
               if(detailRegexp.exec(screen) != null){
                    alert("inside1");
                    newAction="&omniActionOrTab=Init";
               }else if(tranRegexp.exec(screen) != null){
                    alert("inside2");
                    newAction="omniActionOrTab=Init";
                  alert("inside3");
               document.forms["GoToScreen"].action = pathPrepend + document.forms["GoToScreen"].screenName.value.toUpperCase() + ".do?useSessionKeys=true" + newAction;               
               alert("action = "+document.forms["GoToScreen"].action);
               return true;
          }          

Similar Messages

  • How can I call a servlet method from a javascript function

    I want to call l a servlet method from a javascript function.
    Does any one have an example of code.
    Thinks in advance

    Actually, as long as the servlet returns valid javascript, you can indeed "call it" from the client. It will initiate a request and return the result to the browser.
    This example uses Perl, but it could be easily modified to go to a servlet instead.
    Note that it is only supported in DOM browsers (IE6+/NN6+/etc)
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
    <html>
    <head>
    <title> Test server-side JS </title>
    </head>
    <body>
    <script type="text/javascript">
    function checkIt(variable, value)
    var newScript = "cgi-bin/validateJS.cgi?"+variable+"="+value;
    var body = document.getElementsByTagName('body').item(0)
    var scriptTag = document.getElementById('loadScript');
    if(scriptTag) body.removeChild(scriptTag);
    script = document.createElement('script');
    script.src = newScript;
         script.type = 'text/javascript';
         script.id = 'loadScript';
         body.appendChild(script)
    </script>
    <p>Test.</p>
    <form id="f1" action="">
    <input type="text" name="t1" id="t1" onChange="checkIt(this.name, this.value)">
    </body>
    </html>
    validateJS.cgi
    #!/opt/x11r6/bin/perl
    use CGI qw(:all);
    my @valArray = split(/=/,$ENV{QUERY_STRING});
    print "Content-type: text/javascript\n\n";
    # myPass is the password
    $myPass = "foobar";
    if ("$valArray[1]" eq "$myPass")
    print "alert(\"Success!!\")";
    else
    print "alert(\"Failure!!\")";

  • Set multiple items with javascript function in chart link

    Hi Folks
    I am able to use the javascript $s function to set the value of one item from a chart link. I need to pass values to multiple items.
    Is there a way to use javascript function to pass values for multiple items on a page from a chart link
    Appreciate your responses
    Thanks
    Gopal

    Hi Arnau,
    You need to surround your JavaScript code like this (without the spaces before and after script):
    < script language="Javascript">
      window.open("<%=ABAP_VARIABLE%>").focus();
    </script >
    Regards,
    Patrick.

  • Javascript-function doesn't work with user nobody

    I recently started to use AJAX with APEX. I defined a Application Process and a Javascript-Function which fetch values from a Lookup-Table into some fields, which works great. Except when I make the page available public (user nobody), then it doesn't work anymore.

    Hello,
    Do you have page 0 (zero) in your application? If you are using page 0 as a parameter in your htmldb_Get function, the page must be public (http://htmldb.oracle.com/pls/otn/f?p=11933:63).
    Regards,
    Arie.

  • How to pass value to pop up window using javascript function?

    I am not sure how to do this, I want to open new window from existing form,This is Mod/PLsql for consists some javascript functions also. When I am clicking on new window in form then new form should open with results of value entered,but new window form is opening with main page :( , not able to get text box value from parent form. How to call textbox input value in popup window from parent window using javascript?
    currently I'm using following code:
    HTP.p('<script type="text/javascript">
    function pop_up5()
    var l_url=window.opener.document.getElementById("p_single_store_pc").value;
    window.open(l_url, '''', ''fullscreen=no, scrollbars=1'');
    </script>' );
    Edited by: user11970612 on Jun 14, 2012 5:02 AM

    this is probably due to the Javascript code and not a "real link" to another page... I don't know if the null is due to the Javascript...
    But if you really really want to use javascript instead of a ... you can pass the location of the url with JSP (on your main page) as a parameter to the open window... (...) u can put instead of main.jsp <%= request.getServerName()+request.getRequestURI() %>
    the value <%= ... %> will return something like test.com/html/main.jsp
    Hope this helps.

  • JavaScript function which fetches return_value from List of Values

    Hi,
    I have created List of Values named "NICKS". I want to write JavaScript function "get_workers_fullname(nick)" which returns display_value from List of Values. The parameter of function is return_value of List "NICKS".
    I am new with this and don't know how to handle this case.
    Please help me.

    Hi,
    The LOV, I mean is the item in Application's Shared Components. I don't mean the visible SelectList on the page.
    This is what I found in ApEx's help: "A List of Values can be referenced by page items as well as report fields. It controls the values displayed and limits the user's selection. Lists of Values can be static (based on values you enter) or dynamic (based on a SQL query)."
    I'd like to access values in such LOV from JavaScript. I am not sure it is possible.
    Cheers,
    Tom.

  • Passing value from javascript function to servlet

    Hello everybody,
    i need to pass parameter from javascript function to servlet.
    what i wrote is :
    function callPopulateServlet(t)
    var h =document.NewRequest.services;
    var y = t.selectedIndex;
    alert(h.options[y].value);
    var id=h.options[y].value;
    <%session.setAttribute("id",id);%> // am getting error at this point
    document.NewRequest.submit();
    with this id am quering values from database through servlet.
    any body knows plz help me.
    thanks,
    anil.

    this is the error am getting
    Stacktrace:
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
         org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:435)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:299)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

  • Assigning return value of a javascript function to a variable

    hi.
    I have a javascript function which returns string.
    I wanna assing return value of that function to variable.
    for example:
    <script>
    funtion writeMe()
    var ex;
    ex="try"
    return ex;
    </script>
    Then in body of JSP page. I wanna do something like:
    <% String st;%>
    Now I wanna assign the value that returned from writeMe function ("try") to st string.like:
    <%st= writeMe();%>. but of course it doesn't work. how can I do that?

    thnx. but actually what I want to do is sending some values produced by javascript to a barchart object. is it impossible too?
    I mean my script function returns something like "100, 200, 300". I wanna pass that values to barchart. when I want to add aplet tag to jsp code instead of writing:
    <param name="s1_value" value="100,200,300">
    I want to write somethin like:
    <param name="s1_value" value="myscriptfunction()">
    is it possible in JSP? I saw an example like this in asp. it was like:
    <param name="sampleLabels" value="<%call func1()>">. but in JSP it seems like call tag doesn't work. Is it possible in JSP?

  • JavaScript Function to validate an item's value

    Can somebody please tell me how to write a Javascript Function that, upon losing focus on a text item, checks if the value just entered is a 6 digit number?
    Please show me the function and what the onblur command in the item would be. The name of the item is P21_PERMIT_NUMBER.
    BTW, this can't be done in a Validation, since it must be done onblur, which does not submit the page.
    Also, if there already is an onKeyPress for this item, what do I do? Do I just put a comma after the onKeyPress command and write the onblur command after it?
    Thanks.

    Prohan,
    Take a look at the following link to see how to do validation within a javascript function: Re: Implementing in-field validation the simple way.
    Thank you,
    Tony Miller
    Webster, TX

  • Using Javascript function to change the value of a request variable

    Have a javascript function that activates onchange within a form variable. Would like the javascript function to change the value of a request variable.
    The javascript function is able to obtain the current value of the request variable ( which is 0 ) however I am unsuccessful in changing the value to 1.
    I have been trying to use the following:
         var vchange = 'request.changes_made = 1 ;' ;
         eval(vchange);
    Any ideas?

    If the user makes a change to the content of the form, and then attempts to leave the form, a javascript alert pops up giving the user the option of cancelling the submit, returning to the form and saving it.
    If there have been no changes, then the user is free to migrate to another page.
    This process is to protect users from losing valuable information but not to annoy them with "R U Sure" messages.
    Knowing the status of the form content is important to the functionality of the application.
    G

  • How to return javascript function value to jsp page

    Hi i want to retrieve values from javascript function to jsp page, how can i do that ? i am trying this but its not working
    <script language="javascript" type="text/javascript" src="/feedback/common/scripts/config.js"></script>
    <script language="javascript" type="text/javascript" src="/feedback/common/scripts/richtext.js"></script>
    <td>
    <jsp:param id="description" value= "<%=request.initRTE('', '')%>"/>
    </td>
    here this initRTE function is used for displaying rich text editor .....i want to retrieve back the contetnt written in this editor and save it to DB.
    Please help.
    Edited by: xtech on Apr 4, 2008 12:00 PM

    surely i will do that but my app is still not working.....
    here is my code
    </td>
    <td align="left">
    <script language="javascript" type="text/javascript" src="/feedback/common/scripts/config.js"></script>
    <script language="javascript" type="text/javascript" src="/feedback/common/scripts/richtext.js"></script>
    <h:inputHidden id="introtext" value= "<%=request.getParameterValues(description)%>">
    <script>
    initRTE('','');
    </script>
    </td>
    in java script function i am geeting the text content
    function initRTE(rtePreloadContent, rteCSS) {
    rtePreloadContent=document.getElementById('surveyinfo:introtext').value;
    startRTE(rtePreloadContent);
    menuBuilder();
    var description= document.getElementById(rteFormName).value;
    return description;
    basically i want to get the text written in text editor in jsp and want to send it to DB.(Here initRTE() function is calling rich text editor)
    i have downloaded this editor from this url
    http://freerichtexteditor.com/page/4.htm
    and trying to embed it in my app.

  • How to get value stored in  javascript function and display in a JSP

    i am doing a questionaire which is for user to input data in every question, After user input the data, a javascript function will be called to do some score calculation. Since each question will carry its final score after the calculation by the javascript function, so i use an array to store those scores and then display those scores in the same page.
    However, i have to make a confirmation page to display both data and calculated score in another jsp, i only know how to display the data as it is a textfield that i can get the value by "request.getParameter("textfield1"); but i dun know how to get those scores as they are stored in an array in the javascript function, what way i can do??

    thank you for all your help!
    I have chosen to set the score value to the hidden field when every time run the function
    <script language="javascript">
    function cal(index){
    var thisForm = document.MC;
    thisForm.score1.value=score[index];//set value to the hidden field     
    </script>
    <input type="hidden" name="score1" value="">
    <input type="hidden" name="score2" value="">
    <input type="hidden" name="score3" value="">
    The function will calculate only one score when every time being called. So that i can only assign one score to one hidden value at a time.
    e.g, assign score[1] to thisForm.score1.value
    assign score[2] to thisForm.score2.value
    assign score[3] to thisForm.score3.value
    how can i do this??

  • Calling a javascript function from java code and getting tha value in Java

    Hi,
    I would like to call a Java script function confirmRemove() from Java code upon meeting a condition..
    for example the code snippet is:
    if(true){
    // I want to call js confirmRemove() over here. And get the value of variable "answer" in this if block.
    <html>
    <head>
    <script type="text/javascript">
    function confirmRemove() {
         var answer = confirm("Are you sure you want to Delete?")
    </script>
    </head>
    <body>
    <form>...

    Hi,
    Back in 2003 I have used an Applet which contain java code and this java code was calling the java scripts ( different methods, DHTML etc..)
    There was a component developed by NetScape called JSObject I am not sure it there is other third party component other then the JSObject
    look at this article which shows how (based on JSObject)
    [http://java.sun.com/products/plugin/1.3/docs/jsobject.html|http://java.sun.com/products/plugin/1.3/docs/jsobject.html]
    Regards,
    Alan Meio
    London,UK

  • How to pass value from Javascript function to a Java class method

    Hi All,
    I want to pass a value, which I catch in a Javascript function to a method in a Java class. I have tried many combinations but it gives me error.
    This is the way I am doing
    function assignBill() {
    proj = projPh.substring(0,indSlash);
    <% myproject.getProj(" project_cd = '" + proj + "'");%>
    proj is the variable which I want to pass to getProj methods.
    If any one has done this, please let me know. Thanks for your help.
    Ritesh Mehta

    The only way to receive something from clients page is to submit it somehow: through a form or link, but the info has to make it back to the server obviously. I dont know how your app works, but you can use the the javascript -location.href- function(i think) to submit the var to the server and process it there.

  • Select list display value in javascript function

    Hi All,
    I have a select list in a tabular form having a display value & return value.
    I am using $x(var_name).value or $v(var_name) for retreving return value of the select list in a javascript function.
    Can anyone let me know how can I get the display value of the select list in a javascript function? Im using Apex 3.2
    Thanks & Regards,
    Sandeep

    What if the select list is not an item. Select list I am talking about is in a tabular form.Regardless of how they're generated in APEX, in JavaScript they're all DOM nodes. There are many ways of accessing the node of the required element. Consider the Items for Order... tabular form on page 29 of the Sample Application:
    var productNameLOV = document.wwv_flow.f04[0] // select list containing name of product on first order line
    var productNameLOV = $x("f04_0001") // another way of accessing the same node, using the ID attribute generated by apex_itemWe can see this using the Safari console:
    => productNameLOV = document.wwv_flow.f04[0]
        <select name="f04" id="f04_0001" autocomplete="off">…</select>
    => productNameLOV = $x("f04_0001")
        <select name="f04" id="f04_0001" autocomplete="off">…</select>Once you've got the node&mdash;however you get it&mdash;you then use the methods shown above:
    => i = productNameLOV.selectedIndex
        3
    => productNameLOV.options.text
    "Business Shirt [$50]"
    So it appears you would use:var item = document.wwv_flow.f01[i];
    var selected = item.selectedIndex;
    var selectedOption = item.options[selected].text;
    This is meaningless:...
    var my_var = document.wwv_flow.f01[i].id; // f01 is tabular column of select list
    if ($x(my_var) == 'display_value') //$x(my_var) is having return value, but i need display_value there
    <tt>$x(my_var)</tt> returns a DOM node object, whilst <tt>'display_value'</tt> is a string: they are not comparable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for

  • Automatic PO at the time of GRN

    Dear expert, Anybody please tell me where the no range of  automatically generated PO is maintained.I am generating automatic PO in Transaction code MB01 in mvt type 101. Regards, ABHI

  • How to restrict data for selection

    Hi, folk, I've faced with the following issue. I have set of items. There are, for example, income items and expense items. Items are distinguished by value of attribute. According to business process, planning for income and expense items is quite d

  • No accounting document exist in excise invoice

    Hi everyone, I am able to create excise invoice,but no accounting document existing for that excise invoice.So because of that no accounting entry is coming in the excise invoice.So what should be setting for above problem. Regards Prabudh

  • HT203167 I cant find the movie I purchased

    I purchased the movie batman I lost my old phone now I have another phone I cant find it in my icloud account... Please help!!!

  • Data Controls Missing From View Controller Tab

    Good Afternoon, I have researched for hours over the internet and this forum but have not found an answer. My problem is this: I am using JDeveloper Studio Edition Version 11.1.2.1.0. In my ViewController project no Data Controls are displayed in the