adding image based on if condition specifically to input box without opening new page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 123123om
    New Member
    • Apr 2012
    • 14

    adding image based on if condition specifically to input box without opening new page

    Hi All,

    this is my client code,
    Code:
    <li>
    <label for="city"><span class="required">City/State</span></label>
    <input id="city" name="city" type="text" class="text required" disabled="disabled">
    </li>
    this is my server side code,
    Code:
    function handler(evtXHR)
    {
      if(xhr.readyState == 4)
       {
         if(xhr.status == 200)
          {
             var response = xhr.responseXML;
             //var response =  xhr.responseText;
             console.log(response);
             toggleDiv("page");
             toggleDiv("pageDtl");
             $("input#city").val(response.getElementsByTagName("city").item(0).firstChild.data);
             
    var desc = response.getElementsByTagName("desc").item(0).firstChild?response.getElementsByTagName("desc").item(0).firstChild.data : "";
             if(desc == "Cloudy")
             {
                 alert("cloudy");
                 $("input#desc").val(response.getElementsByTagName("desc").item(0).firstChild?response.getElementsByTagName("desc").item(0).firstChild.data :);
    document.write("<img src='images/sunny.gif'>");
    here i have if condition to check the weather forecast and its working but i also wanted to add image @ specific location that means in input box but the document.write opens a new page. please somebody help me how to add image in javascript based on if condition without navigating the page to locate the image in input box of server side
    Last edited by Dormilich; Apr 13 '12, 11:46 AM. Reason: Please use [CODE] [/CODE] tags when posting code.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    a) JavaScript (including AJAX) is client-side code
    b) trash document.write( ). it kills your page. use jQuery to insert the image

    Comment

    • johny10151981
      Top Contributor
      • Jan 2010
      • 1059

      #3
      as dormilich said, if you document.write, it will remove all the data from your page and add the certain information.

      and you know that you can give id to any object on the document. why dont you initiate a different id to all the objects, and you simply can write your data to that desired object.

      as example:
      Code:
      $('#your_object').html(data);
      if you use above jquery code you will get one advantages. your embedded javascript code returned from the server will also be executed.

      Comment

      • 123123om
        New Member
        • Apr 2012
        • 14

        #4
        Hi johny10151981,
        could you let me know how and where to use this
        Code:
        $('#your_object').html(data);

        Comment

        Working...