Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Edit html permanently

Options
  • 18-06-2015 5:04pm
    #1
    Registered Users Posts: 3,971 ✭✭✭


    Hi,
    I have been looking all over the internet for answers to this one but I can only find answers that tell me how to add/remove html elements dynamically. I know how to do this but I want to add divs directly to the source of the page and save it so it stays there permanently.
    In the page under document.ready it goes to a JSON file and counts a number of elements in there. When it gets that number it creates that number of divs in the page. It's not possible to do it in Javascript but it is possible in php I think.
    Does anyone have any pointers?


Comments

  • Registered Users Posts: 6,250 ✭✭✭Buford T Justice


    lukin wrote: »
    Hi,
    I have been looking all over the internet for answers to this one but I can only find answers that tell me how to add/remove html elements dynamically. I know how to do this but I want to add divs directly to the source of the page and save it so it stays there permanently.
    In the page under document.ready it goes to a JSON file and counts a number of elements in there. When it gets that number it creates that number of divs in the page. It's not possible to do it in Javascript but it is possible in php I think.
    Does anyone have any pointers?

    You want the web server to have write access to re-write its own files?


  • Registered Users Posts: 1,931 ✭✭✭PrzemoF


    I don't really understand what you want to do as you're using words "dynamically" and "permanently". Probably what you want is php [1], but it would be easier to answer you question if you could provide an example.

    [1] http://www.bluemoosetech.com/php-and-mysql.php?jid=11&title=How%20does%20PHP%20Work


  • Registered Users Posts: 3,971 ✭✭✭lukin


    You want the web server to have write access to re-write its own files?

    It's a web page running on localhost, it's not going online but yes I want the html page to have a script that runs on page load and adds divs to itself (not dynamically). I don't even know if this is possible. It would have to remove them when the page closes as the amount of divs required each time it loads may change (depends on the JSON).


  • Registered Users Posts: 3,971 ✭✭✭lukin


    PrzemoF wrote: »
    I don't really understand what you want to do as you're using words "dynamically" and "permanently". Probably what you want is php [1], but it would be easier to answer you question if you could provide an example.

    [1] http://www.bluemoosetech.com/php-and-mysql.php?jid=11&title=How%20does%20PHP%20Work

    The page loads a JSON file that contains counties and towns. When I click on a county it takes me to a div that contains a list of towns in those counties (kind of like an anchor in the page). But the number of counties can change from time to time so the number of divs must change accordingly. I am able to add the divs dynamically (using JQuery.append) but the divs are not displayed in the source this way. So the anchor does not work. I need to write html directly to the source (as if I were writing to a text file).


  • Closed Accounts Posts: 2,743 ✭✭✭blatantrereg


    Changing the page programmatically is what dynamically means.

    If you want the html itself to be different on load rather than changing it with a script then you want to generate the html in the first place using server side code, for example php as mentioned above.

    It would probably be easier to do it that way, but there would be no meaningful difference in the end result between that and adding them with a script. HTML generated with a script wouldn't be searchable by google etc but that's not relevant if you are only using it on localhost.


  • Advertisement
  • Registered Users Posts: 1,931 ✭✭✭PrzemoF


    How you're adding the anchor? A quick search for jquery + anchor shows that it should work. I guess that the anchor is your main problem and you think writing html is the solution?


  • Registered Users Posts: 3,971 ✭✭✭lukin


    Seems like php is the way to go thanks guys.


  • Registered Users Posts: 306 ✭✭yes there


    Could you just toggle div visibilty?


  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    lukin wrote: »
    It's a web page running on localhost, it's not going online but yes I want the html page to have a script that runs on page load and adds divs to itself (not dynamically). I don't even know if this is possible. It would have to remove them when the page closes as the amount of divs required each time it loads may change (depends on the JSON).

    So it is dynamic - adding and removing divs that way is exactly what dynamic means.

    The way most modern web developers would do this is to have a skeletal page which is dynamically drawn based on the contents of the JSON, retrieving updates & changed data using AJAX. I don't know what you mean when you say you can't make the anchor tag work - it's quite normal to build a web page this way, including with links and anchors and photos and bnlocks of text and all the other bits & pieces you might expect.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    lukin wrote: »
    I am able to add the divs dynamically (using JQuery.append) but the divs are not displayed in the source this way. So the anchor does not work. I need to write html directly to the source (as if I were writing to a text file).
    OK, it's all 'dynamic', you're just getting confused with the terminology.

    The core difference between using the JQuery approach and a language like PHP is that the former is client-side and the latter is server-side. If your aim is to have the content accessible from the HTML source, this is important because of how the code is executed.

    Client-side code is sent to the browser and executed there, so if you look at the source, you'll see un-executed code - what was sent to the browser. Server-side code is executed on the server and only the resultant HTML is sent to the browser, hence when you look at the source then, you'll see your counties as this is what was sent to the browser.

    So any server-side technology (PHP, Java, Ruby, etc) will do the trick, depending upon your overall setup. Only thing I would sanity check is why you need to be able to see everything in your source, as it may be easier to achieve what you want without having to resort to server side development.


  • Advertisement
Advertisement